package 项目版本管理实践;
import java.util.Scanner;
public class PasswordDemo{
    public static void main(String[] args) {                      //程序入口
        Scanner sc = new Scanner(System.in);
        int num=0;
        //循环
        while(num!=5) {
            System.out.println("==============================");
            System.out.println("      欢迎使用密码管理系统");
            System.out.println("==============================");
            System.out.println("请选择操作：");
            System.out.println("    1. 加密\n" +
                    "    2. 解密\n" +
                    "    5. 退出\n");
            System.out.print("请输入选项序号：");
            num = sc.nextInt();
            String pw;
            char[] charArr = new char[0];
            System.out.println("==============================");
            System.out.println("      欢迎使用密码管理系统");
            System.out.println("==============================");
            if(num==1){                                          //条件——密码加密
                System.out.print("请输入要加密的数字密码：");
                pw = sc.next();
                StringBuilder sb1=new StringBuilder();
                charArr =pw.toCharArray();
                System.out.print("加密后的结果是：");
                for(int i=0;i<charArr.length;i++){
                    char temp =(char)(charArr[i]+(i+1)+3);
                    sb1.append(temp);
                }
                char c=sb1.charAt(0);
                sb1.setCharAt(0,sb1.charAt(charArr.length-1));
                sb1.setCharAt(charArr.length-1,c);
                System.out.println(sb1.reverse().toString());
                System.out.println("按任意键返回");
                sc.next();
            } else if (num==2) {                                  //条件——密码解密
                StringBuilder sb2 = new StringBuilder();
                System.out.print("请输入要解密的数字密码：");
                pw = sc.next();
                sb2.append(pw);
                charArr = pw.toCharArray();
                char c = sb2.charAt(0);
                sb2.setCharAt(0, sb2.charAt(charArr.length - 1));
                sb2.setCharAt(charArr.length - 1, c);
                charArr = sb2.reverse().toString().toCharArray();
                for (int i = 0; i < charArr.length; i++) {
                    char temp = (char) (charArr[i] - (i + 1) - 3);
                    sb2.setCharAt(i, temp);
                }
                System.out.println("解密后的结果是：" + sb2.toString());
                System.out.println("按任意键返回");
                sc.next();
            } else if (num==5) {                                   //条件——程序结束
                System.out.println("程序结束");
                break;
            }
        }
        sc.close();
    }
}
